var e = require;
var t = module;
var n = exports;
var o,
    i =
        (this && this.__extends) ||
        ((o = function (e, t) {
            return (o =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var n in t) Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
                })(e, t);
        }),
        function (e, t) {
            function n() {
                this.constructor = e;
            }
            o(e, t), (e.prototype = null === t ? Object.create(t) : ((n.prototype = t.prototype), new n()));
        }),
    r =
        (this && this.__decorate) ||
        function (e, t, n, o) {
            var i,
                r = arguments.length,
                a = r < 3 ? t : null === o ? (o = Object.getOwnPropertyDescriptor(t, n)) : o;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(e, t, n, o);
            else
                for (var s = e.length - 1; 0 <= s; s--)
                    (i = e[s]) && (a = (r < 3 ? i(a) : 3 < r ? i(t, n, a) : i(t, n)) || a);
            return 3 < r && a && Object.defineProperty(t, n, a), a;
        },
    a =
        (this && this.__awaiter) ||
        function (e, a, s, c) {
            return new (s = s || Promise)(function (n, t) {
                function o(e) {
                    try {
                        r(c.next(e));
                    } catch (e) {
                        t(e);
                    }
                }
                function i(e) {
                    try {
                        r(c.throw(e));
                    } catch (e) {
                        t(e);
                    }
                }
                function r(e) {
                    var t;
                    e.done
                        ? n(e.value)
                        : ((t = e.value) instanceof s
                              ? t
                              : new s(function (e) {
                                    e(t);
                                })
                          ).then(o, i);
                }
                r((c = c.apply(e, a || [])).next());
            });
        },
    s =
        (this && this.__generator) ||
        function (n, o) {
            var i,
                r,
                a,
                s = {
                    label: 0,
                    sent: function () {
                        if (1 & a[0]) throw a[1];
                        return a[1];
                    },
                    trys: [],
                    ops: []
                },
                e = {next: t(0), throw: t(1), return: t(2)};
            return (
                "function" == typeof Symbol &&
                    (e[Symbol.iterator] = function () {
                        return this;
                    }),
                e
            );
            function t(t) {
                return function (e) {
                    return (function (t) {
                        if (i) throw new TypeError("Generator is already executing.");
                        for (; s; )
                            try {
                                if (
                                    ((i = 1),
                                    r &&
                                        (a =
                                            2 & t[0]
                                                ? r.return
                                                : t[0]
                                                ? r.throw || ((a = r.return) && a.call(r), 0)
                                                : r.next) &&
                                        !(a = a.call(r, t[1])).done)
                                )
                                    return a;
                                switch (((r = 0), (t = a ? [2 & t[0], a.value] : t)[0])) {
                                    case 0:
                                    case 1:
                                        a = t;
                                        break;
                                    case 4:
                                        return s.label++, {value: t[1], done: !1};
                                    case 5:
                                        s.label++, (r = t[1]), (t = [0]);
                                        continue;
                                    case 7:
                                        (t = s.ops.pop()), s.trys.pop();
                                        continue;
                                    default:
                                        if (
                                            !(a = 0 < (a = s.trys).length && a[a.length - 1]) &&
                                            (6 === t[0] || 2 === t[0])
                                        ) {
                                            s = 0;
                                            continue;
                                        }
                                        if (3 === t[0] && (!a || (t[1] > a[0] && t[1] < a[3]))) {
                                            s.label = t[1];
                                            break;
                                        }
                                        if (6 === t[0] && s.label < a[1]) {
                                            (s.label = a[1]), (a = t);
                                            break;
                                        }
                                        if (a && s.label < a[2]) {
                                            (s.label = a[2]), s.ops.push(t);
                                            break;
                                        }
                                        a[2] && s.ops.pop(), s.trys.pop();
                                        continue;
                                }
                                t = o.call(n, s);
                            } catch (e) {
                                (t = [6, e]), (r = 0);
                            } finally {
                                i = a = 0;
                            }
                        if (5 & t[0]) throw t[1];
                        return {value: t[0] ? t[1] : void 0, done: !0};
                    })([t, e]);
                };
            }
        };
Object.defineProperty(n, "__esModule", {value: !0});
var c,
    l = e("index"),
    u = e("events"),
    p = e("sound"),
    h = e("player-coin"),
    d = e("player-info"),
    f = e("player-theme"),
    m = e("big-coin"),
    t = cc._decorator,
    e = t.ccclass,
    t = t.property,
    e =
        ((c = cc.Component),
        i(y, c),
        (y.prototype.start = function () {
            u.operEvent.on(this.onOperTap.bind(this));
        }),
        (y.prototype.onOperTap = function (e) {
            var t, n, o;
            null != e &&
                null != e.action &&
                u.default.upgrade == e.action &&
                null != e.data &&
                ((n = new Date()),
                (o = d.playerInfo.getStartTime()),
                (t = n.getTime() - o),
                (t = Math.round((0.001 * t) / 60)),
                (n = d.playerInfo.getUseResetCount()),
                (o = d.playerInfo.getUseADAreaCount()),
                l.platform.trackEvent("passLevel", {
                    level: d.playerInfo.getLevel() - 1,
                    level_time: t,
                    useReset: n,
                    useADArea: o,
                    videoNum: n + o
                }),
                this.playUpgrade(e.data.num),
                d.playerInfo.setStartTime(0),
                d.playerInfo.setUseResetCount(0),
                d.playerInfo.setUseADAreaCount(0));
        }),
        (y.prototype.playUpgrade = function (e) {
            var t = new h.coinData();
            (t.cellIdx = 0), (t.isUnknown = !1), (t.num = e), this.bigCoin ? this.apperBigCoin(t) : this.loadBigCoin(t);
        }),
        (y.prototype.apperBigCoin = function (e) {
            var t = this;
            this.bigCoin.init(e),
                (this.bigCoin.node.opacity = 255),
                (this.bigCoin.node.scale = 1),
                this.bigCoin.node.setPosition(0, 0),
                (this.bigCoin.node.active = !0),
                this.isLoadFirework ? this.playFirework() : this.loadFirework(),
                p.sound.play(p.Sound.MERGE10),
                this.bigCoin.playApper(function () {
                    t.moveBigCoin();
                });
        }),
        (y.prototype.loadFirework = function () {
            return a(this, void 0, void 0, function () {
                var t, n, o, i, r, a;
                return s(this, function (e) {
                    switch (e.label) {
                        case 0:
                            return [4, l.ResUtil.loadPrefab("prefab/prefab/Firework")];
                        case 1:
                            for (t = e.sent(), n = 0; n < this.fireworkNode.length; n++)
                                for (
                                    o = this.fireworkNode[n],
                                        (i = cc.instantiate(t)).parent = o,
                                        i.setPosition(0, 0),
                                        r = o.getComponentsInChildren(cc.ParticleSystem),
                                        a = 0;
                                    a < r.length;
                                    a++
                                )
                                    r[a].stopSystem();
                            return this.playFirework(), [2];
                    }
                });
            });
        }),
        (y.prototype.playFirework = function () {
            for (var e = this, t = 0; t < this.fireworkNode.length; t++)
                !(function (n) {
                    var o = e.fireworkNode[n];
                    cc.tween(o)
                        .delay(e.fireworkDelays[n])
                        .call(function () {
                            0 === n && p.sound.play(p.Sound.WIN);
                            for (var e = o.getComponentsInChildren(cc.ParticleSystem), t = 0; t < e.length; t++)
                                e[t].resetSystem();
                        })
                        .start();
                })(t);
        }),
        (y.prototype.moveBigCoin = function () {
            var e = this.bigCoin.node,
                t = this.targetNode.convertToWorldSpaceAR(cc.Vec2.ZERO),
                n = e.parent.convertToNodeSpaceAR(t),
                t = [];
            t.push(cc.v2(e.x, e.y)),
                t.push(cc.v2(e.x + this.coinOffPosition.x, e.y + this.coinOffPosition.y)),
                t.push(n);
            (t = cc.bezierTo(this.coinMoveTime, t)),
                (t = cc.spawn(
                    t,
                    cc.scaleTo(this.coinMoveTime, this.bigCoinEndScale),
                    cc.fadeTo(this.coinMoveTime, this.bigCoinEndOpacity)
                ));
            cc.tween(e)
                .then(t)
                .delay(0.1)
                .call(function () {
                    u.operEvent.emit({action: u.default.unlocknLast, data: {}}), (e.active = !1);
                })
                .start();
        }),
        (y.prototype.loadBigCoin = function (n) {
            return a(this, void 0, void 0, function () {
                var t;
                return s(this, function (e) {
                    switch (e.label) {
                        case 0:
                            return (
                                (t = f.playerTheme.getCurThemeName()),
                                [4, l.ResUtil.loadPrefab("prefab/prefab/" + t + "/big-coin")]
                            );
                        case 1:
                            return (
                                (t = e.sent()),
                                ((t = cc.instantiate(t)).parent = this.bigCoinStartNode),
                                (this.bigCoin = t.getComponent(m.default)),
                                this.apperBigCoin(n),
                                [2]
                            );
                    }
                });
            });
        }),
        r([t(cc.Node)], y.prototype, "bigCoinStartNode", void 0),
        r([t(cc.Node)], y.prototype, "targetNode", void 0),
        r([t(cc.Node)], y.prototype, "fireworkNode", void 0),
        r([t([cc.Float])], y.prototype, "fireworkDelays", void 0),
        r([t(cc.Float)], y.prototype, "coinMoveTime", void 0),
        r([t(cc.Vec2)], y.prototype, "coinOffPosition", void 0),
        r([t], y.prototype, "bigCoinEndScale", void 0),
        r([t], y.prototype, "bigCoinEndOpacity", void 0),
        r([e], y));
function y() {
    var e = (null !== c && c.apply(this, arguments)) || this;
    return (
        (e.bigCoinStartNode = null),
        (e.targetNode = null),
        (e.fireworkNode = []),
        (e.fireworkDelays = []),
        (e.coinMoveTime = 0.5),
        (e.coinOffPosition = new cc.Vec2(100, 100)),
        (e.bigCoinEndScale = 0.1),
        (e.bigCoinEndOpacity = 10),
        (e.bigCoin = null),
        (e.isLoadFirework = !1),
        e
    );
}
n.default = e;
